<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="客户姓名" prop="cName">
        <el-input v-model="form.cName" placeholder="请输入客户姓名" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="身份证号" prop="idcardNum">
        <el-input v-model="form.idcardNum" placeholder="请输入身份证信息" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="送机时间" prop="postTime">
        <el-date-picker
          style="width: 260px"
          v-model="form.postTime"
          type="datetime"
          placeholder="选择日期时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="客户类型" prop="cType">
        <el-select v-model="form.cType" placeholder="请选择" style="width: 260px">
          <el-option label="家庭用户" value="1"></el-option>
          <el-option label="单位用户" value="2"></el-option>
          <el-option label="代理商" value="3"></el-option>
          <el-option label="签约用户" value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="座机" prop="cCall">
        <el-input v-model="form.cCall" placeholder="请输入座机号码" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入手机号码" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="邮编" prop="postNum">
        <el-input v-model="form.postNum" placeholder="请输入邮政编码" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="form.email" placeholder="请输入邮箱账号" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="单位名称" prop="unitName">
        <el-input v-model="form.unitName" placeholder="请输入客户单位名称" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="cAddress">
        <el-input type="textarea" v-model="form.cAddress" placeholder="请输入客户地址" style="width: 260px"></el-input>
      </el-form-item>
     <el-form-item style="margin-top: 20px">
        <el-button type="primary" @click="submitForm('form')">提交</el-button>
        <el-button @click="resetForm('form')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
// import RichText from '@/components/RichText/RichText'
import {addUser} from '../../api/client'
//import {setMap} from '../../utils/dataStorage'

export default {
  
  data() {
    return {
      form: {
        cId: "",
        cName: "",
        idcardNum: "",
        postTime: "",
        cType: "",
        cCall: "",
        phone: "",
        postNum: "",
        email: "",
        unitName: "",
        cAddress: "",
        active:"1"
        //createTime: ""
      },
      rules: {
        cName: [
          { required: true, message: "请输入客户姓名", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1-10个字符", trigger: "blur" }
        ],
        idcardNum: [
          { required: true, message: "请输入客户身份证号", trigger: "blur" }
        ],
        postTime: [
          {
            type: "date",
            required: true,
            message: "请选择客户送机日期",
            trigger: "change"
          }
        ],
        cType: [
          { required: true, message: "请选择客户类型", trigger: "blur" }
        ],
        
        postNum: [
          { required: true, message: "请输入邮编", trigger: "blur" }
        ],
        email: [
          { required: true, message: "请输入电子邮箱", trigger: "blur" }
        ],
        
        cAddress: [
          { required: true, message: "请输入单位地址", trigger: "blur" }
        ],
      },

    };
  },
  created(){},
  components: {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          // 设置提交的参数
          let param = new URLSearchParams();
          param.append("cName", this.form.cName);
          param.append("idcardNum", this.form.idcardNum);
          let time = this.form.postTime
          let year = time.getFullYear();
          let month = time.getMonth()+1;
          let day = time.getDate();
          time = year + "-" + month + "-" + day + " " +"00:00:00";
          param.append("postTime",time);
          param.append("cType", this.form.cType);
          param.append("cCall",this.form.cCall);
          param.append("phone",this.form.phone);
          param.append("postNum",this.form.postNum);
          param.append("email",this.form.email);
          param.append("unitName",this.form.unitName);
          param.append("cAddress",this.form.cAddress);
          param.append("active",this.form.active);
          let that = this;
          addUser(param).then(r=>{
            setTimeout(() => {
              this.$notify({
                title:"新增客户成功",
                type:"success"
              });
              //this.$router.push({ path: "/dclient/list"});
            },1000);
          }).catch(_=>{
              console.log(r);
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName){
        this.$refs[formName].resetFields();
    },
  }
};
</script>